<?php

namespace App\Models\Elasticsearch\Settlement;

use App\Models\Elasticsearch\Model;

class Detail extends Model
{

    const INDEX_NAME = 't_settlement_detail';

    /**
     * 获取游戏详情
     *
     * @param string $roundId
     * @return array|null
     */
    protected function getDetail(string $roundId): ?array
    {
        $params = ['body' => ['size' => 1, 'track_total_hits' => false]];
        // 数据筛选
        $params['body']['query']['bool']['must'][] = [
            'term' => ['round_id' => $roundId]
        ];
        // 查询数据
        $results = $this->search($params);

        // 详情数据
        $detail = $results['hits']['hits'][0]['_source'] ?? null;

        // 解析JSON
        if (isset($detail['details'])) {
            $detail['details'] = json_decode($detail['details'], true);
        }

        return $detail;
    }
}
